#pragma comment(lib, "engine.lib")
#include <Core.h>
#include "Game.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int nShowCmd)
{
	MSG msg;

	// Game creation happens here	
    Game instance(hInstance, nShowCmd);
	game = &instance;

	game->initialise();		// initialise game
	game->loadContent();	// load game content

	__int64 cntsPerSec = 0;
	QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);	// get processor cycles
	float secsPerCnt = 1.0f / (float)cntsPerSec;			// determine secs per cycle

	__int64 prevTimeStamp = 0;
	QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);	// get initial game time
	__int64 currTimeStamp = 0;

	while (true)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))	// check for message
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);		// process message			
		}
		if (msg.message == WM_QUIT)
			break;

		QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);	// get time passed since
		float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt;	// last frame update

		game->update(dt);		// update game with current game time
		game->render();			// render frame

		prevTimeStamp = currTimeStamp;		// set initial game time ready for next frame
	}

	game->unloadContent();		// unload game content

	return msg.wParam;
}